//
//  HYTableViewCell.m
//  TJHYHardwareProduct
//
//  Created by Kendama on 2018/1/22.
//  Copyright © 2018年 Kendama. All rights reserved.
//

#import "HYWarningRecordTableViewCell.h"
#import "HYWarnInfoModel.h"

#define fontSize 15
@implementation HYWarningRecordTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)updateDataWithWarnInfoModel:(HYWarnInfoModel *)model
{
    self.deviceIDLabel.text = model.dno;
    self.warnTimeLabel.text = model.ctime;
    self.companyLabel.text = model.company_name;
    self.deviceLocationLabel.text = [NSString stringWithFormat:@"%@%@%@%@栋%@层%@房",model.province,model.city,model.district,model.dong,model.ceng,model.fang];
    if ([model.status isEqualToString:@"0"])
    {
        self.stateButton.selected = YES;
    }
    else
    {
        self.stateButton.selected = NO;
    }
}

#pragma mark --- 懒加载
- (UILabel *)deviceID
{
    if(!_deviceID)
    {
        UIView *superView = self.contentView;
        _deviceID = [[UILabel alloc]init];
        [superView addSubview:_deviceID];
        [_deviceID setFont:fontWithSize(fontSize)];
        [_deviceID setTextColor:rgba(1,71,141,0.8)];
        [_deviceID sizeToFit];
        _deviceID.text = @"设备编号：";
    }
    return _deviceID;
}
- (UILabel *)deviceIDLabel
{
    if(!_deviceIDLabel)
    {
        UIView *superView = self.contentView;
        _deviceIDLabel = [[UILabel alloc]init];
        [superView addSubview:_deviceIDLabel];
        [_deviceIDLabel setFont:fontWithSize(fontSize)];
        [_deviceIDLabel setTextColor:rgba(51,51,51,1)];
    }
    return _deviceIDLabel;
}
- (UILabel *)warnTime
{
    if(!_warnTime)
    {
        UIView *superView = self.contentView;
        _warnTime = [[UILabel alloc]init];
        [superView addSubview:_warnTime];
        [_warnTime setFont:fontWithSize(fontSize)];
        [_warnTime setTextColor:rgba(1,71,141,0.8)];
        [_warnTime sizeToFit];
        _warnTime.text = @"报警时间：";
    }
    return _warnTime;
}
- (UILabel *)warnTimeLabel
{
    if(!_warnTimeLabel)
    {
        UIView *superView = self.contentView;
        _warnTimeLabel = [[UILabel alloc]init];
        [superView addSubview:_warnTimeLabel];
        [_warnTimeLabel setFont:fontWithSize(fontSize)];
        [_warnTimeLabel setTextColor:rgba(51,51,51,1)];
    }
    return _warnTimeLabel;
}
- (UILabel *)company
{
    if(!_company)
    {
        UIView *superView = self.contentView;
        _company = [[UILabel alloc]init];
        [superView addSubview:_company];
        [_company setFont:fontWithSize(fontSize)];
        [_company setTextColor:rgba(1,71,141,0.8)];
        [_company sizeToFit];
        _company.text = @"所属企业：";
    }
    return _company;
}
- (UILabel *)companyLabel
{
    if(!_companyLabel)
    {
        UIView *superView = self.contentView;
        _companyLabel = [[UILabel alloc]init];
        [superView addSubview:_companyLabel];
        [_companyLabel setFont:fontWithSize(fontSize)];
        [_companyLabel setTextColor:rgba(51,51,51,1)];
    }
    return _companyLabel;
}
- (UILabel *)deviceLocation
{
    if(!_deviceLocation)
    {
        UIView *superView = self.contentView;
        _deviceLocation = [[UILabel alloc]init];
        [superView addSubview:_deviceLocation];
        [_deviceLocation setFont:fontWithSize(fontSize)];
        [_deviceLocation setTextColor:rgba(1,71,141,0.8)];
        [_deviceLocation sizeToFit];
        _deviceLocation.text = @"设备位置：";
    }
    return _deviceLocation;
}
- (UILabel *)deviceLocationLabel
{
    if(!_deviceLocationLabel)
    {
        UIView *superView = self.contentView;
        _deviceLocationLabel = [[UILabel alloc]init];
        [superView addSubview:_deviceLocationLabel];
        [_deviceLocationLabel setFont:fontWithSize(fontSize)];
        [_deviceLocationLabel setTextColor:rgba(51,51,51,1)];
        _deviceLocationLabel.numberOfLines = 0;
    }
    return _deviceLocationLabel;
}
- (UIButton *)stateButton
{
    if(!_stateButton)
    {
        UIView *superView = self.contentView;
        _stateButton = [[UIButton alloc]init];
        [superView addSubview:_stateButton];
        [_stateButton setTitle:@"已解决" forState:UIControlStateNormal];
        [_stateButton setTitle:@"未解决" forState:UIControlStateSelected];
        [_stateButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_stateButton.titleLabel setFont:fontWithSize(13)];
        [_stateButton setBackgroundImage:imageWithName(@"resolved") forState:UIControlStateNormal];
        [_stateButton setBackgroundImage:imageWithName(@"Out of contact") forState:UIControlStateSelected];
        [_stateButton sizeToFit];
    }
    return _stateButton;
}



#pragma mark --- 布局
- (void)masLayoutSubview
{
    __weak UIView *superView = self.contentView;
    CGFloat edge = px1920Height(50);
    
    [self.stateButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.right.mas_equalTo(superView);
    }];
    
    [self.deviceID mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(superView.mas_top).with.offset(edge);
        make.left.mas_equalTo(superView.mas_left).with.offset(edge);
    }];
    
    [self.deviceIDLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(_deviceID.mas_centerY);
        make.left.mas_equalTo(_deviceID.mas_right).with.offset(edge);
    }];
    
    [self.warnTime mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_deviceID.mas_bottom).with.offset(edge);
        make.left.mas_equalTo(_deviceID.mas_left);
    }];
    
    [self.warnTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(_warnTime.mas_centerY);
        make.left.mas_equalTo(_warnTime.mas_right).with.offset(edge);
    }];
    
    [self.company mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_warnTime.mas_bottom).with.offset(edge);
        make.left.mas_equalTo(_deviceID.mas_left);
    }];
    
    [self.companyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(_company.mas_centerY);
        make.left.mas_equalTo(_company.mas_right).with.offset(edge);
    }];
    
    [self.deviceLocation mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_company.mas_bottom).with.offset(edge);
        make.left.mas_equalTo(_deviceID.mas_left);
    }];
    
    [self.deviceLocationLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_deviceLocation);
        make.left.mas_equalTo(_deviceLocation.mas_right).with.offset(edge);
        make.right.mas_equalTo(superView.mas_right).with.offset(-edge);
        make.height.mas_lessThanOrEqualTo(px1920Height(130));
    }];
    
    
//    _deviceIDLabel.text = @"0001313";
//    _warnTimeLabel.text = @"2017-09-20";
//    _companyLabel.text = @"腾讯科技";
//    _deviceLocationLabel.text = @"深圳市南山区深圳市南山区深圳市南山区深圳市南山区深圳市南山区深圳市南山区深圳市南山区深圳市南山区深圳市南山区深圳市南山区深圳市南山区深圳市南山区深圳市南山区";
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
